package com.summer_administration.controller;

import com.summer_administration.mapper.GroupeMapper;
import com.summer_administration.pojo.Expenses;
import com.summer_administration.pojo.GroupExpenseDTO;
import com.summer_administration.pojo.Groupe;
import com.summer_administration.pojo.Result;
import com.summer_administration.service.ExpensesService;
import com.summer_administration.service.GroupeService;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/groupe")
@Validated
public class GroupeController {
    @Autowired
    private GroupeService groupeService;

    @Autowired
    private GroupeMapper groupeMapper;

    @PostMapping
    public Result add(@RequestBody @Validated Groupe groupe) {
      /*  // 新增一个根剧小组名字查询小组id
        String groupeName = groupe.getGroupName();
        String groupId = groupeMapper.findGroupIdByGroupName(groupeName);
        groupe.setGroupId(groupId);*/
        groupeService.add(groupe);
        return Result.success();
    }

    @GetMapping
    public Result<List<Groupe>> list() {
        List<Groupe> list = groupeService.list();
        return Result.success(list);
    }

    @PutMapping
    public Result update(@RequestBody @Validated Groupe groupe) {
        groupeService.update(groupe);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam Integer id) {
        groupeService.delete(id);
        return Result.success();
    }

    // 新增的接口方法
    @GetMapping("/getDetailByGroupld")  // 分配唯一子路径 /name
    public Result<String> getGroupNameByGroupId(@RequestParam String groupId) {
        String groupName = groupeService.getGroupNameByGroupId(groupId);
        return Result.success(groupName);
    }
}